package cn.signalpha.modules.shop.service;

import cn.signalpha.modules.shop.entity.GoodsSpec;
import cn.signalpha.modules.shop.mapper.GoodsSpecMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

import static cn.signalpha.common.cache.CacheNames.EXPIRATION_TIME_7;
import static cn.signalpha.common.cache.CacheNames.GOODS_SPEC;


/**
 * 商品规格 服务类
 *
 * @author suguangjun
 */
@Service
public class GoodsSpecService extends ServiceImpl<GoodsSpecMapper, GoodsSpec> {

	@Cacheable(cacheNames = GOODS_SPEC + EXPIRATION_TIME_7, key = "#goodsId")
    public List<GoodsSpec> listByGoodsId(Long goodsId) {
        return list(Wrappers.<GoodsSpec>lambdaQuery().eq(GoodsSpec::getGoodsId, goodsId));
    }

	@CacheEvict(cacheNames = GOODS_SPEC, key = "#goodsId")
    public void removeByGoodsId(Long goodsId) {
        baseMapper.delete(Wrappers.<GoodsSpec>lambdaQuery().eq(GoodsSpec::getGoodsId, goodsId));
    }

	@CacheEvict(cacheNames = GOODS_SPEC, key = "#goodsId")
	public void removeCacheByGoodsId(Long goodsId) {
	}
}
